package com.ruoyi.accountant.dao;

import com.ruoyi.accountant.domain.Reason;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface ReasonDao extends TempDao<Reason, Long> {

    /***
     * 根据父节点查询
     * @param rid
     * @return
     */
    List<Reason> findAllByParent(Long rid);

    /***
     * 根据名称查询
     * @param reasonName
     * @return
     */
    Reason findTop1ByRname(String reasonName);

    @Query("from Reason where rid in (select distinct i.ofReason from TransactionDetail as i where i.dtype = ?1 group by i.ofReason)")
    List<Reason> findByIds(String type);

    List<Reason> findAllByLevel(int level);
}
